import React, { Component } from 'react';
import {
	StyleSheet, Text, View, Image, Platform, TouchableOpacity, PixelRatio,
	ActivityIndicator, ScrollView, FlatList, DeviceEventEmitter
} from "react-native";
import { style } from '../../../theme/style';
import { GLOBAL } from '../../../config/global';
import { Common } from '../../../component/common/Common.js';
import MethodUtil from '../../../utils/MethodUtil';

const scale = GLOBAL.SCALE;
const creditType = {
	'SX': '赊销',
	'YF': '预付'
}
export class CreditDetailPage extends Component {
	static navigationOptions = ({ navigation }) => {
		const params = navigation.state.params;

		return {
			headerTitle: params.title,
			headerLeft: <Common type="headLeft" onPress={() => { navigation.goBack() }} color='#fff' />,
			headerStyle: {
				elevation: 0,
				borderBottomWidth: 0,
				backgroundColor: style.color.themeColor,
			},
			headerTintColor: '#fff',
		};
	};

	constructor(props) {
		super(props);
	}

	render () {
		const { params } = this.props.navigation.state;
		const creditInfo = params.creditInfo || {};
		return (
			<View style={styles.container}>
				<View style={styles.companyNameView}><Text style={styles.companyName}>{params.companyName}</Text></View>
				<View style={styles.content}>
					<View style={styles.creditInfoItem}>
						<Text style={styles.creditInfoItemLabel}>授信类型</Text>
						<Text style={styles.creditInfoItemText}>{creditInfo.creditKind ? creditType[creditInfo.creditKind] : '-'}</Text>
					</View>
					<View style={styles.creditInfoItem}>
						<Text style={styles.creditInfoItemLabel}>中信保审批额度</Text>
						<Text style={styles.creditInfoItemText}>{creditInfo.zxbApproveAmount ? ('¥' + MethodUtil.toThousands(creditInfo.zxbApproveAmount || 0) + '元') : '-'}</Text>
					</View>
					<View style={styles.creditInfoItem}>
						<Text style={styles.creditInfoItemLabel}>申请授信额度</Text>
						<Text style={styles.creditInfoItemText}>{creditInfo.creditAmount ? ('¥' + MethodUtil.toThousands(creditInfo.creditAmount || 0) + '元') : '-'}</Text>
					</View>
					<View style={styles.creditInfoItem}>
						<Text style={styles.creditInfoItemLabel}>申请授信天数</Text>
						<Text style={styles.creditInfoItemText}>{(creditInfo.accountDay || '-') + '天'}</Text>
					</View>
					<View style={styles.creditInfoItem}>
						<Text style={styles.creditInfoItemLabel}>授信有效期至</Text>
						<Text style={styles.creditInfoItemText}>{creditInfo.creditEndDate || '-'}</Text>
					</View>
					<View style={styles.creditInfoItem}>
						<Text style={styles.creditInfoItemLabel}>当年交易额</Text>
						<Text style={styles.creditInfoItemText}>{creditInfo.dealAmount ? ('¥' + MethodUtil.toThousands(creditInfo.dealAmount || 0) + '元') : '-'}</Text>
					</View>
					<View style={styles.creditInfoItem}>
						<Text style={styles.creditInfoItemLabel}>常用结算方式</Text>
						<Text style={styles.creditInfoItemText}>{creditInfo.settlementType || '-'}</Text>
					</View>
					<View style={styles.creditInfoItem}>
						<Text style={styles.creditInfoItemLabel}>交易利润</Text>
						<Text style={styles.creditInfoItemText}>{creditInfo.dealProfit ? ('¥' + MethodUtil.toThousands(creditInfo.dealProfit || 0) + '元') : '-'}</Text>
					</View>
					<View style={styles.creditInfoItem}>
						<Text style={styles.creditInfoItemLabel}>预计今年最大单笔交易额</Text>
						<Text style={styles.creditInfoItemText}>{creditInfo.dealMaxAmount ? ('¥' + MethodUtil.toThousands(creditInfo.dealMaxAmount || 0) + '元') : '-'}</Text>
					</View>
					<View style={styles.creditInfoItem}>
						<Text style={styles.creditInfoItemLabel}>备注</Text>
						<Text style={styles.creditInfoItemText}>{creditInfo.remark || '-'}</Text>
					</View>
				</View>
			</View>
		)
	}
}

const styles = StyleSheet.create({
	container: {
		backgroundColor: '#FFF'
	},
	companyNameView: {
		backgroundColor: style.color.themeColor,
		paddingTop: 28 * scale,
		paddingLeft: 36 * scale,
		paddingBottom: 14 * scale,
	},
	companyName: {
		color: '#fff',
		fontSize: 14 * scale,
		fontWeight: '600'
	},
	content: {
		paddingLeft: 23 * scale,
		paddingTop: 18 * scale,
	},
	creditInfoItem: {
		flexDirection: 'row',
		marginBottom: 14 * scale
	},
	creditInfoItemLabel: {
		flex: 1,
		fontSize: 14 * scale,
		color: '#000',
		paddingRight: 28 * scale
	},
	creditInfoItemText: {
		flex: 2,
		fontSize: 16 * scale,
		color: '#000',
		fontWeight: '600'
	}
})